package com.wsd.smartcarwasher.util;


import com.alibaba.fastjson.JSONObject;

import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;




public class MapUtils {


    public static String showMap(String origins,String destinations,
                                       HttpServletRequest request) throws UnsupportedEncodingException {
        Map<String, String> params = new HashMap<String, String>();
//        String originDouble = HttpClientUtil
//                .doGet("http://api.map.baidu.com/geocoder/v2/?output=json&ak=AI1iVTkp7jUn47iq7lsY2ZG1uIBvXqQG&address="
//                        +origins );
//        String desDouble = HttpClientUtil
//                .doGet("http://api.map.baidu.com/geocoder/v2/?output=json&ak=AI1iVTkp7jUn47iq7lsY2ZG1uIBvXqQG&address="
//                        + destinations);
//        JSONObject jsonObjectOri = JSONObject.parseObject(originDouble);
//        JSONObject jsonObjectDes = JSONObject.parseObject(desDouble);
//        String oriLng = jsonObjectOri.getJSONObject("result").getJSONObject("location").getString("lng");// 经度值ֵ
//        String oriLat = jsonObjectOri.getJSONObject("result").getJSONObject("location").getString("lat");// 纬度值ֵ
//
//        String desLng = jsonObjectDes.getJSONObject("result").getJSONObject("location").getString("lng");
//        String desLat = jsonObjectDes.getJSONObject("result").getJSONObject("location").getString("lat");
//        params.put("output", "json");//输出方式为json
//        params.put("tactics", "11");//10不走高速11常规路线12 距离较短（考虑路况）13距离较短（不考虑路况）
//        params.put("ak", "自己的ak");
//        // origins 起点 destinations 目的地
//        params.put("origins", oriLat + "," + oriLng + "|" + oriLat + "," + oriLng);
//        params.put("destinations", desLat + "," + desLng + "|" + desLat + "," + desLng);

//      String result = HttpClientUtil.doGet("http://api.map.baidu.com/directionlite/v1/driving?origin="+origins+"&destination="+destinations+"&ak=AI1iVTkp7jUn47iq7lsY2ZG1uIBvXqQG");
        String url="http://api.map.baidu.com/directionlite/v1/driving?origin="+origins+"&destination="+destinations+"&ak=9KqvVKKuk6PAhFudOliGOiEmsEcWIPEX";
        url= url.replaceAll(" ", "%20");
        String result = HttpClientUtil.doGet(url);


        if (StringUtil.isEmpty(result))
        {
            return "";
        }

        JSONObject jsonObject = JSONObject.parseObject(result);
        JSONObject jsonObject1= JSONObject.parseObject(jsonObject.getString("result"));
        String distance=jsonObject1.getJSONArray("routes").getJSONObject(0).get("distance").toString();
        return distance;
    }


}

